﻿package com.shootingGame.weaponsClasses
{
	import com.shootingGame.weaponsClasses.ordinance.Ordinance;
	
	import flash.utils.getDefinitionByName;
	
	public class WeaponInfo
	{
		
		public var launchprofile : String;
		public var ammoMax : int;
		private var _ammoCount : int;
		public var ordinanceSpeed : Number;
		public var damage : Number;
		public var coolDownTime : int;
		private var _coolDownTimeCount : int;		
		public var clipSize : int;
		private var _clipCount : int;
		public var ammoPerShot : int;
		private var _accuracy : Number;
		private var _minAccuracy : Number;
		private var _maxAccuracy : Number;
		private var _accuracyDegradeRate : Number;
		private var _accuracyRecoverRate : Number;
		public var spinUpTime : Number;
		private var  _spinUpTimeCount : Number;
		public var chargeMax : int;
		private var _chargeRate : Number; //amount to charge per millisecond the primary mouse button is depressed.
		private var chargeCount : Number;
		private var _turningRate : Number; //in degrees
		private var numCoolDownSteps : int;
		public var ordinanceSample : Ordinance;
		
		public function WeaponInfo(launchProf : String, ordSpd : Number, mxAmo : int,
						ammoCount : int, dmg : Number, coolTim : int, clpSiz : int = int.MAX_VALUE, amoPrShot : int = 1,
						mnAcc : Number = 1, mxAcc : Number = 1, accDecRt : Number = 0,
						accIncRt : Number = 1, spinUpTim = 0, chrgMx = 0, chrgRt = 0, turnRt = 0)
		{
		this.launchprofile = launchProf;
		this.ammoMax = mxAmo;
		this._ammoCount = ammoCount;
		this.ordinanceSpeed = ordSpd;
		this.damage = dmg;
		this.coolDownTime = coolTim;
		this._coolDownTimeCount = 0;
		this.clipSize = clpSiz;
		_clipCount = clpSiz;
		this.ammoPerShot = amoPrShot;
		minAccuracy = mnAcc;
		maxAccuracy = mxAcc;
		this.accuracy = maxAccuracy;
		_accuracyDegradeRate = accDecRt;
		_accuracyRecoverRate = accIncRt;
		this.spinUpTime = spinUpTim;
		_spinUpTimeCount = 0;
		this.chargeMax = chrgMx;
		this.chargeRate = chrgRt;
		chargeCount = 0;
		this.turningRate = turnRt;
		}
		
		public function get clipCount() : int{
			return _clipCount;
		}
		
		public function shotsFired() : Boolean {
			if(_clipCount > ammoPerShot){
				_clipCount -= ammoPerShot;
				_ammoCount -= ammoPerShot;
				accuracy -= _accuracyDegradeRate;
				numCoolDownSteps = 0;
				return true;
			}
			return false;
		}
		
		public function get ammoCount() : int{
			return _ammoCount;
		}
		
		public function set ammoCount(value : int) {
			if(value > ammoMax)
				value = ammoMax;
			ammoCount = value;
		}
		
		public function get coolDownTimeCount() : int{
			return _coolDownTimeCount;
		}
		
		public function set coolDownTimeCount(value : int) : void{
			_coolDownTimeCount = value;
			if(_coolDownTimeCount<0){
				if(_accuracy < _maxAccuracy){
					var numCoolDownSteps_Now : int = (-_coolDownTimeCount) / int(coolDownTime);
					if(numCoolDownSteps_Now > numCoolDownSteps){
						numCoolDownSteps = numCoolDownSteps_Now;
						accuracy += _accuracyRecoverRate;
					}
				}	
			}
		}
		
		public function get accuracy() : Number{
			return _accuracy;
		}
		
		public function set accuracy(value : Number) {
			_accuracy = value;
			if(_accuracy < _minAccuracy)
				_accuracy = _minAccuracy;
			else
				if(_accuracy > _maxAccuracy)
					_accuracy = _maxAccuracy;
		}
		
		public function get maxAccuracy() : Number{
			return _maxAccuracy;
		}
		
		public function set maxAccuracy(value : Number) {
			_maxAccuracy = value;
			if(_maxAccuracy < 0)
				_maxAccuracy = 0.1;
			else
				if(_maxAccuracy > 1)
					_maxAccuracy = 1;			
		}
		
		public function get minAccuracy() : Number{
			return _minAccuracy;
		}
		
		public function set minAccuracy(value : Number) {
			_minAccuracy = value;
			if(_minAccuracy < 0)
				_minAccuracy = 0.1;
			else
				if(_minAccuracy > 1)
					_minAccuracy = 1;			
		}		
		
		public function get spinUpTimeCount() : Number{
			return _spinUpTimeCount;
		}
		
		public function set spinUpTimeCount(value : Number) {
			_spinUpTimeCount = value;
			if(_spinUpTimeCount < 0)
				_spinUpTimeCount = 0;
		}
		
		public function get chargeRate() : int{
			return _chargeRate;
		}
		
		public function set chargeRate(value : int) {
			if(value > chargeMax)
				value = chargeMax;
			_chargeRate = value;
		}
		
		public function get turningRate() : Number{
			return _turningRate;
		}
		
		public function set turningRate(value : Number) {
			_turningRate = value;
			if(_turningRate < 0)
				_turningRate = 0;
			else
				if(_turningRate >= 360)
					_turningRate = _turningRate % 360;
		}


	}
}